part of base_package;

class TimeUtil {
  /// 获取现在日期时间
  static String nowTime() {
    String nowTime = DateTime.now().toString();
    return nowTime = nowTime.substring(0, nowTime.lastIndexOf("."));
  }

  /// 获取现在时间戳，10位，不含毫秒
  static int nowTimeMilliseconds() {
    return DateTime.now().millisecondsSinceEpoch ~/ 1000;
  }

  /// 不含毫秒的时间戳转时间
  static String millisecondsToTime(int milliseconds) {
    String time =
        DateTime.fromMillisecondsSinceEpoch(milliseconds * 1000).toString();
    return time = time.substring(0, time.lastIndexOf("."));
  }

  /// 获取现在日期
  static String nowDate() {
    String nowTime = DateTime.now().toString();
    return nowTime = nowTime.substring(0, nowTime.lastIndexOf(" "));
  }

  /// 时间转时间戳
  static int dateToTimeMilliseconds(String date) {
    return DateTime.parse(date).millisecondsSinceEpoch ~/ 1000;
  }

  /// 时间截取 yyyy-MM-dd hh:mm
  /// date : yyyy-MM-dd hh:mm:ss
  static String time2yyyyMMddhhmm(String date) {
    return date.substring(0, date.length - 3);
  }
}
